/**
 * Author : Kalounet
 */
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.URL;
import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import com.jgoodies.looks.LookUtils;
import com.jgoodies.looks.plastic.Plastic3DLookAndFeel;
import com.jgoodies.looks.plastic.PlasticLookAndFeel;
import com.jgoodies.looks.plastic.PlasticXPLookAndFeel;
import com.jgoodies.looks.plastic.theme.ExperienceBlue;
import com.jgoodies.looks.windows.WindowsLookAndFeel;

import mv.releaser.controler.ConfigObject;
import mv.releaser.controler.ControlerMvReleaser;
import mv.releaser.model.MvReleaser;

public class Main {

	private static ConfigObject	config;

	public static void main(String[] args) {

		readConfig();
		setLookAndFeel();
		MvReleaser mvReleaser = new MvReleaser();
		ControlerMvReleaser controler = new ControlerMvReleaser(mvReleaser,
				config);
	}

	private static void setLookAndFeel() {
		try {
			UIManager.installLookAndFeel("Plastic 3D",
					"com.jgoodies.looks.plastic.Plastic3DLookAndFeel");
			UIManager.installLookAndFeel("Plastic",
					"com.jgoodies.looks.plastic.PlasticLookAndFeel");
			UIManager.installLookAndFeel("Plastic XP",
					"com.jgoodies.looks.plastic.PlasticXPLookAndFeel");

			String jvmVersion = System.getProperties().getProperty(
					"java.vm.version");
			String name = System.getProperty("os.name");

			if (config != null) {
				UIManager.setLookAndFeel(config.getLookAndFeel());
			} else {
				boolean natif = true;
				if (name.equals("Linux") && jvmVersion.charAt(2) < '6') {
					natif = false;
				}

				 if (natif)
					UIManager.setLookAndFeel(UIManager
							.getSystemLookAndFeelClassName());
				else {
					UIManager
							.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
				}
			}

		} catch (Exception e) {
			System.out.println(e.getMessage());
			e.printStackTrace();
		}
	}

	private static void readConfig() {
		config = null;
		try {
			// ouverture d'un flux d'entrée depuis le fichier "personne.serial"
			FileInputStream fis = new FileInputStream("config.data");
			// création d'un "flux objet" avec le flux fichier
			ObjectInputStream ois = new ObjectInputStream(fis);
			try {
				// désérialisation : lecture de l'objet depuis le flux d'entrée
				config = (ConfigObject) ois.readObject();
			} finally {
				// on ferme les flux
				try {
					ois.close();
				} finally {
					fis.close();
				}
			}
		} catch (IOException ioe) {
			ioe.printStackTrace();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		}

		if (config != null)
			System.out.println(config + " a ete deserialise");
	}
}
